package com.abe.libquick.widget.dialog;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Window;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.abe.libcore.view.common.BaseDialog;
import com.abe.libquick.R;

public class MessageDialog extends BaseDialog {
    private TextView itemTitle, itemContent, itemClose;
    private String title, content;

    public MessageDialog(@NonNull Context context) {
        super(context);
    }

    public MessageDialog(@NonNull Context context, String title, String content) {
        super(context);
        setTitle(title);
        setContent(content);
    }

    public static MessageDialog init(@NonNull Context context, String title, String content) {
        return new MessageDialog(context, title, content);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.item_view_dialog_message_show);
        itemTitle = findViewById(R.id.item_v_title);
        itemContent = findViewById(R.id.item_v_content);
        itemClose = findViewById(R.id.item_close);
        if (!TextUtils.isEmpty(title)) {
            itemTitle.setText(title);
        }
        if (!TextUtils.isEmpty(content)) {
            itemContent.setText(content);
        }
        itemClose.setOnClickListener(v -> {
            dismiss();
        });
    }

    public void setTitle(String title) {
        this.title = title;
        if (!TextUtils.isEmpty(title) && itemTitle != null) {
            itemTitle.setText(title);
        }
    }

    public void setContent(String content) {
        this.content = content;
        if (!TextUtils.isEmpty(content) && itemContent != null) {
            itemContent.setText(content);
        }
    }
}
